package cn.kogee.controller;

import cn.kogee.domian.Store;
import cn.kogee.service.IStoreService;
import cn.kogee.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class Storecontroller {
    @Autowired
    private IStoreService storeService;
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody Store Store){
        try {
            if(Store.getId()==null){//添加
                storeService.add(Store);
            }else{
                storeService.update(Store);
            }
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }
    }
    @GetMapping("/{id}")
    public Store loadById(@PathVariable("id") Long id){

        return storeService.findById(id);
    }
    @GetMapping("/pro/{id}")
    public Store loadByProId(@PathVariable("id") Long id){

        return storeService.loadByProId(id);
    }
}
